<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef"> </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from "vue";
import secureGridmessageManage from "@/api/secure/secureGridmessageManage";
import { Message } from "@arco-design/web-vue";
import tool from "@/utils/tool";
import * as common from "@/utils/common";

const crudRef = ref();

const numberOperation = (newValue, id, numberName) => {
  secureGridmessageManage
    .numberOperation({ id, numberName, numberValue: newValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

const switchStatus = (statusValue, id, statusName) => {
  secureGridmessageManage
    .changeStatus({ id, statusName, statusValue })
    .then((res) => {
      res.success && Message.success(res.message);
    })
    .catch((e) => {
      console.log(e);
    });
};

const options = reactive({
  id: "flyos_secure_gridmessage_manage",
  rowSelection: {
    showCheckedAll: true,
  },
  pk: "id",
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: "modal",
    width: 600,
  },
  api: secureGridmessageManage.getList,
  recycleApi: secureGridmessageManage.getRecycleList,
  add: {
    show: true,
    api: secureGridmessageManage.save,
    auth: ["secure:gridmessageManage:save"],
  },
  edit: {
    show: true,
    api: secureGridmessageManage.update,
    auth: ["secure:gridmessageManage:update"],
  },
  delete: {
    show: true,
    api: secureGridmessageManage.deletes,
    auth: ["secure:gridmessageManage:delete"],
    realApi: secureGridmessageManage.realDeletes,
    realAuth: ["secure:gridmessageManage:realDeletes"],
  },
  recovery: {
    show: true,
    api: secureGridmessageManage.recoverys,
    auth: ["secure:gridmessageManage:recovery"],
  },
  import: {
    show: true,
    url: "secure/gridmessageManage/import",
    templateUrl: "secure/gridmessageManage/downloadTemplate",
    auth: ["secure:gridmessageManage:import"],
  },
  export: {
    show: true,
    url: "secure/gridmessageManage/export",
    auth: ["secure:gridmessageManage:export"],
  },
});

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入ID",
    },
  },
  {
    title: "区域名称",
    dataIndex: "region_name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入区域名称",
    },
  },
  {
    title: "负责人",
    dataIndex: "duty_id",
    align: "center",
    formType: "select",
    search: false,
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: "system/user/remote",
      // 指定组件接收的props
      props: { label: "nickname", value: "id" },
      // 开启分页
      openPage: true,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ["id", "nickname"],
        // 设置数据过滤
        filter: {
          wx_user_type: 8,
        },
        // 关联模型
        relations: [],
      },
      translation: true,
    },
  },
  {
    title: "电话",
    dataIndex: "phone",
    formType: "input",
  },
  {
    title: "范围",
    dataIndex: "scope",
    formType: "textarea",
  },
  {
    title: "责任清单",
    dataIndex: "duty_info",
    formType: "textarea",
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true,
  },
]);
</script>
<script>
export default { name: "secure:gridmessageManage" };
</script>
